using GraphProcessor;
using IQIGame.Onigao.Logic;
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

namespace IQIGame.Onigao.GamePlay.Editors
{
    [System.Serializable, NodeMenuItem(LevelEditorConst.Execution + "/【过期】增删服务", typeof(LevelServiceGraph))]
    [Obsolete]
    public class LevelServiceExecutionNode_AddOrDeleteService : LevelServiceExecutionNode
    {
        protected override ServiceExecutionType mServiceType => (ServiceExecutionType)9;

        public override string name => "/【过期】增删服务";
        [Output("目标", false)] public EditorLevelServiceTargetSetter tagOrMcid;
        [LevelServiceEditorCustomProperty((ServiceExecutionType)9, "是增加还是删除"), Tooltip("0：删除，1：增加，2：删除所属服务")]
        public int type;
        public List<ServiceEditorNode> services;

        protected override LevelServiceCustomConfig CreateConfig()
        {
            var rConfig = new LevelServiceExecutionCustom_AddOrDeleteService()
            {
                type = this.type,
                services = this.services.Select(x => x.groupID).ToList(),
            };
            tagOrMcid = new EditorLevelServiceTargetSetter((x) => rConfig.tagOrMcid = x);

            return rConfig;
        }

        [Serializable]
        public class ServiceEditorNode
        {
            public BaseGraph graph;
            [LevelServiceEditorCustomProperty(LevelEditorConst.ServiceEditorNode, "服务列表", nameof(graph))]
            public int groupID;
        }

        protected override void OnSync(EditorLevelServiceExecutionConfig newConfig, LevelServiceExecutionNode tempNode)
        {
            if (tempNode is LevelServiceExecutionNode_AddOrDeleteService rNode)
            {
                this.type = rNode.type;
                this.services = new List<ServiceEditorNode>(rNode.services);
            }
            if (newConfig.customConfig is LevelServiceExecutionCustom_AddOrDeleteService rConfig)
            {
                this.SyncTarget(rConfig.tagOrMcid, nameof(tagOrMcid));
            }
        }
    }
}